package com.wwy.arithmetic.suanfa;

import com.wwy.arithmetic.suanfa.entry.TreeNode;

/**
 * 树中的路径总和
 * 5
 * 3    8
 * 2  4 6  9
 */
public class LuJingZongHe {

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(5);
        TreeNode treeNode1 = new TreeNode(3);
        TreeNode treeNode2 = new TreeNode(1);
        TreeNode treeNode3 = new TreeNode(4);
        TreeNode treeNode4 = new TreeNode(8);
        TreeNode treeNode5 = new TreeNode(6);
        TreeNode treeNode6 = new TreeNode(9);

        treeNode.setLeft(treeNode1);
        treeNode.setRight(treeNode4);
        treeNode1.setLeft(treeNode2);
        treeNode1.setRight(treeNode3);
        treeNode4.setLeft(treeNode5);
        treeNode4.setRight(treeNode6);
        boolean judge = judgeNum(0, new TreeNode());
        System.out.println("judge = " + judge);
    }

    static boolean judgeNum(Integer num, TreeNode node) {
        return judge(num, node);
    }

    static boolean judge(int num, TreeNode leftNode) {
        if (leftNode == null) {
            return false;
        }
        if (leftNode == null) {
            return false;
        }
        return judge(num - leftNode.getVal(), leftNode.getLeft()) || judge(num - leftNode.getVal(), leftNode.getRight());

    }
}
